<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/11
 * Time: 14:42
 */

namespace app\index\controller;
use think\Controller;
use think\Db;

class Sjk extends Controller
{
    public function sjk(){
        //链表查询
//       $hh =  Db::table('carts')
//            ->alias('c')
//            ->join('goods g','c.good_id = g.good_id')
//            ->join('guige e','c.g_id = e.g_id')
//            ->select();


      //子查询 in
 //$hh = Db::table('carts')->where('c_id in (1,2)')->select();
       // $hh = Db::table('carts')->where()->select();


 //删除表
//        $sql = 'drop table us';
//     Db::table('')->query($sql);

    }
    public function dd(){
        //查询一例的数据
     // $hh =  Db::table('carts')->column('num');

        //模糊查询
        $hh =  Db::table('goods')->where("name like '重%庆'")->select();
    var_dump($hh);exit;
    }
    public function kk(){

//        sql中的判断语句 ，数据库高级查询    数据库索引
//        case when then case when then esle end       in()子查询       column 取出某一个列数据     like 模糊查询
//
//        $data = Db::table('goods')
//            ->field('CASE `g_sn` WHEN 1 THEN 1111111 ELSE 222222 END AS num')
//            ->field('g_sn,name,good_id')
//            ->select();
//        var_dump($data);
        $data = Db::table('goods')
            ->where('good_id',1)
            ->where('good_id = 1')
            ->select();
        var_dump($data);

    }
    public function update_info(){
        $data = Db::table('name')->where('id = 1')->find();
        $this ->assign('data',$data);
        return $this->fetch('Sjk/index');
    }
    public function update(){
        $data = Db::table('name')->where('id = '.$_POST['id'])->find();
        $info = array(
            'name' => $_POST['name'] == ''?$data['name']:$_POST['name']
        );
        $id = Db::table('name')->insertGetId($info);
        if($id){
            $this->success();
        }else{
            $this->error();
        }
    }
    public function update_info1(){
        $data = Db::table('name')->where('id = 1')->find();
        $this ->assign('data',$data);
        if(!empty($_POST['id'])){
            $info = array(
                'name' => $_POST['name'] == ''?$data['name']:$_POST['name']
            );
            $id = Db::table('name')->insertGetId($info);
            if($id){
                $this->success();
            }else{
                $this->error();
            }
        }
        return $this->fetch('Sjk/index');
    }
}